<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>在线聊天</title>
</head>
<body>
<div>
    <textarea id="msgBox" name="textarea" style="width: 400px; height: 600px; font-size: 20px;"></textarea>
    <input id="msg" type="text">
    <button>发送信息</button>
</div>
</body>
<script>
    let ws = new WebSocket('ws://127.0.0.1:5732/ws');
    let msgBox = document.getElementById('msgBox');
    let btn = document.querySelector('button');
    let msg = document.getElementById('msg');
    btn.onclick = function () {
        ws.send(msg.value);
        // msgBox.innerHTML += msg.value + '\n';
    }
    //收到信息
    ws.onmessage = function (message) {
        console.log(message.data);
        msgBox.innerHTML = message.data + '\n';
    }
</script>
</html>